package cxt.com.recyclerview.demo4;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import cxt.com.recyclerview.R;

/**
 * 坑：RecyclerView局部更新时，闪屏
 */


public class MainActivity4 extends AppCompatActivity {
    private RecyclerView mRecyclerView;
    private List<Image> mImage;
    private ImageAdapter mImageAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        initView();
    }

    private void initView() {
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mImageAdapter = new ImageAdapter(mImage = initData());

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(mImageAdapter);

    }


    public List<Image> initData() {
        List<Image> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Image image = new Image();
            image.setImgid(R.drawable.bg);
            image.setName("bg");
            list.add(image);
        }
        return list;
    }
}
